package com.example.worldgdpjar.service;

import com.example.worldgdpjar.dao.CountryLanguageDao;
import com.example.worldgdpjar.model.CountryLanguage;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountryLanguageService {
  private final CountryLanguageDao countryLanguageDao;

  public CountryLanguageService(CountryLanguageDao countryLanguageDao) {
    this.countryLanguageDao = countryLanguageDao;
  }

  public List<CountryLanguage> getLanguages(String countryCode, Integer pageNo) {
    final int pageSize = 10;
    int offset = (pageNo - 1) * pageSize;
    return countryLanguageDao.getLanguages(countryCode, offset, pageSize);
  }

  public boolean languageExists(String countryCode, String language) {
    int count = countryLanguageDao.getLanguageCount(countryCode, language);
    return count != 0;
  }
}
